<template>
	<a-drawer
		title="日志"
		:width="1200"
		:visible="visible"
		:destroy-on-close="true"
		:footer-style="{ textAlign: 'right' }"
		@close="onClose"
	>
		<s-table ref="table" :columns="columns" :data="loadData" bordered>
			<template #bodyCell="{ column, record }">
				<template v-if="column.dataIndex === 'fullname'">
					{{ record.cabinetGroupName }} {{ record.cabinetInfoName }} {{ record.cabinetDoorName }}
				</template>
				<template v-if="column.dataIndex === 'remark'">
					<span v-if="record.operation === '申请'">申请天数：{{ record.applyDays }}</span>
					<span v-if="record.operation === '授权'">授权期限：{{ record.permStartTime }}~{{ record.permEndTime }}</span>
					<span v-if="record.operation === '拒绝'">拒绝原因：{{ record.refuseReason }}</span>
					<span v-if="record.operation === '冻结'">
						冻结时间：{{ record.frozenDays }}天，冻结原因：{{ record.frozenReason }}
					</span>
					<span v-if="record.operation === '选择用户授权'">
						授权期限：{{ record.permStartTime }}~{{ record.permEndTime }}
					</span>
					<span v-if="record.operation === '选择用户冻结'">
						冻结时间：{{ record.frozenDays }}天，冻结原因：{{ record.frozenReason }}
					</span>
				</template>
			</template>
		</s-table>
	</a-drawer>
</template>

<script setup name="cabinetpermissionlog">
	import { message } from 'ant-design-vue'
	import tool from '@/utils/tool'
	import bizCabinetPermissionLogApi from '@/api/biz/bizCabinetPermissionLogApi'

	const record = ref()
	const isApplyRecordOnly = ref(false)
	const table = ref()
	const visible = ref(false)
	const columns = [
		{
			title: '操作',
			dataIndex: 'operation'
		},
		{
			title: '操作人',
			dataIndex: 'operationUserName'
		},
		{
			title: '操作时间',
			dataIndex: 'operationTime'
		},
		{
			title: '备注',
			dataIndex: 'remark'
		}
	]
	const loadData = (parameter) => {
		let searchFormParam
		if (isApplyRecordOnly.value) {
			searchFormParam = {
				userId: record.value.userId,
				// cabinetGroupId: record.value.cabinetGroupId,
				cabinetInfoId: record.value.cabinetInfoId
				// cabinetDoorId: record.value.cabinetDoorId,
				// permState: 'UNAUTHORIZED'
			}
		} else {
			searchFormParam = { permissionId: record.value.id }
		}
		// console.log(searchFormParam)
		return bizCabinetPermissionLogApi
			.bizCabinetPermissionLogPage(Object.assign(parameter, searchFormParam))
			.then((data) => {
				return data
			})
	}
	// 打开抽屉
	const onOpen = (_record, _isApplyRecordOnly) => {
		visible.value = true
		record.value = _record
		isApplyRecordOnly.value = _isApplyRecordOnly
	}
	// 关闭抽屉
	const onClose = () => {
		visible.value = false
	}
	// 抛出函数
	defineExpose({
		onOpen
	})
</script>
